package com.dba.example.guice.web.rest;

import java.util.List;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.dba.example.entities.Company;
import com.dba.example.guice.beans.OrderBy;
import com.dba.example.guice.beans.Page;
import com.dba.example.guice.beans.PageRequest;
import com.dba.example.guice.dao.CompanyDao;

@Path("/company")
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
public class CompanyResource {

	private CompanyDao companyDao;
	
	@Inject
	public CompanyResource(CompanyDao companyDao) {
		this.companyDao = companyDao;
	}
	
	@GET
	@Path("/list")
	public List<Company> list() {
		return companyDao.list();
	}

	@GET
	@Path("/page")
	public Page<Company> page(@QueryParam("offset") int offset, @QueryParam("size") int size, @QueryParam("sortColumn") String sortColumn, @QueryParam("sortDirection") String sortDirection, @QueryParam("search") String search) {
		return companyDao.page(new PageRequest(offset, size, new OrderBy(sortColumn, sortDirection)), search);
	}

	@GET
	@Path("/get")
	public Company get(@QueryParam("id") Integer id) {
		return companyDao.get(id);
	}
	
	@POST
	@Path("/save")
	public Company save(Company company) {
		return companyDao.save(company);
	}
	
}
